import { chooseImage, compressImage, previewImage, saveImageToPhotosAlbum } from "@tarojs/taro";
class Image {
    constructor() {
    }
    /**
     * 图片选择
     * 拍照 | 相册
     * @param count     图片选择个数
     */
    choose(count) {
        return new Promise((resolve, reject) => {
            chooseImage({
                sizeType: ['compressed'],
                sourceType: ['album', 'camera'],
                count: count !== null && count !== void 0 ? count : 1,
                success: (res) => {
                    resolve(res.tempFilePaths);
                },
                fail: () => {
                    reject();
                },
            }).then(() => {
            });
        });
    }
    /**
     * 压缩
     * @param url
     */
    compress(url) {
        return new Promise((resolve) => {
            compressImage({
                src: url,
                quality: 50,
                compressedWidth: 400,
                success: (res) => {
                    return resolve(res.tempFilePath);
                }
            }).then(() => {
            });
        });
    }
    /**
     * 预览图片
     * @param urls
     * @param index
     */
    preview(urls, index) {
        return new Promise(resolve => {
            previewImage({
                urls: urls,
                current: urls[index],
                //  是否支持长按下载图片
                enablesavephoto: true,
                //  是否在右下角显示下载入口
                enableShowPhotoDownload: true,
                success: () => {
                    return resolve();
                },
                fail: (res) => {
                    console.log('fail', res);
                }
            }).then(() => {
            });
        });
    }
    /**
     * 保存至相册
     * @param filePath
     */
    saveToPhotos(filePath) {
        return new Promise((resolve, reject) => {
            saveImageToPhotosAlbum({
                filePath,
                success: () => {
                    return resolve(true);
                },
                fail: err => {
                    console.log('err', err);
                    return reject(err);
                }
            }).then();
        });
    }
}
export default new Image();
